/*   The MIT License
 *   
 *   Carina Common
 *   Copyright (c) 2010-2011 Zdravko Velinov
 *   
 *   Permission is hereby granted, free of charge, to any person obtaining a copy
 *   of this software and associated documentation files (the "Software"), to deal
 *   in the Software without restriction, including without limitation the rights
 *   to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 *   copies of the Software, and to permit persons to whom the Software is
 *   furnished to do so, subject to the following conditions:
 *
 *   The above copyright notice and this permission notice shall be included in
 *   all copies or substantial portions of the Software.
 *
 *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 *   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 *   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 *   AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 *   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 *   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 *   THE SOFTWARE.
 */

#ifndef GLOBAL_HH_
#define GLOBAL_HH_

#include "carina/common/config.hh"

#ifdef _MSC_VER
#   pragma warning (disable : 4996)
#   define _CRT_SECURE_NO_DEPRECATE
#endif

#include <type_traits>
#include <memory>

using std::alignment_of;
using std::weak_ptr;
using std::shared_ptr;
using std::static_pointer_cast;
using std::const_pointer_cast;
using std::enable_shared_from_this;
using std::unique_ptr;

#include <string>

namespace Carina
{
    typedef std::string string;
}

#define STATIC_ASSERT static_assert

#if defined(HAS_SSE) || defined(HAS_ARM_NEON)
#   ifdef _MSC_VER
#       define SIMD128_ALIGNED __declspec(align(16))
#   else
#       define SIMD128_ALIGNED __attribute__((aligned(16)))
#   endif
#else
#   define SIMD128_ALIGNED
#endif

#ifdef _WIN32
#   define HOME_DIR "APPDATA"
#   define CONFIG_FILE "\\Carina\\carina_config.cfg"
#   define LOG_FILE "\\Carina\\carina_log.txt"
#   define PATH_DELIM '\\'
#elif defined(LINUX)
#   define HOME_DIR "HOME"
#   define CONFIG_FILE "/.carina_config.cfg"
#   define LOG_FILE "/.carina_log.txt"
#   define PATH_DELIM '/'
#else
#   error "Unsupported platform"
#endif

#define _TO_STRING(s) # s
#define TO_STRING(s) _TO_STRING(s)

#define _CONCAT_MACRO(lhs, rhs) lhs##rhs
#define CONCAT_MACRO(lhs, rhs) _CONCAT_MACRO(lhs, rhs)

#ifndef NDEBUG
#   define CE_DEBUG_EXEC_ONCE static bool CONCAT_MACRO(test, __LINE__) = true; if(CONCAT_MACRO(test, __LINE__) ? CONCAT_MACRO(test, __LINE__) = false, true : false)
//#   define CE_MEMORY_DEBUG
#   define CE_RELOADABLE_RESOURCES
#else
#   define CE_DEBUG_EXEC_ONCE if(0)
#endif

#ifdef HAS_NO_CXX11_EXPLICIT_OVERRIDES
#   define override
#   define final
#endif

#define CE_FIXED_ARRAY_SIZE(arr) sizeof(arr)/sizeof(arr[0])

#endif /* GLOBAL_HH_ */
